From: Jan200101 Date: Sun, 25 Jan 2026 21:33:49 +0000 (+0100) Subject: shell-app: Improve discrete GPU detection X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~39^2~1^2~36 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=60f8a7f6810a8c6d155190077369a268b9de1a7b;p=gnome-shell.git shell-app: Improve discrete GPU detection The original logic only took into account if a GPU is the "Default", meaning the GPU used during boot, which was intended for Laptops with Hybrid Graphics. The new logic uses the new Discrete key to figure out which GPU is the most appropriate to use in order of: - the first non-default GPU if it is discrete - the first discrete GPU if it exists - the first non-default GPU Part-of: --- diff --git a/data/dbus-interfaces/net.hadess.SwitcherooControl.xml b/data/dbus-interfaces/net.hadess.SwitcherooControl.xml index e52bc1a0d..59a889654 100644 --- a/data/dbus-interfaces/net.hadess.SwitcherooControl.xml +++ b/data/dbus-interfaces/net.hadess.SwitcherooControl.xml @@ -38,7 +38,8 @@ will contain a user-facing name for the GPU, the "Environment" (as) key will contain an array of even number of strings, each being an environment variable to set to use the GPU, followed by its value, the "Default" (b) key - will tag the default (usually integrated) GPU. + will tag the default GPU, the "Discrete" (b) key tags if the GPU is a + dedicated component. --> diff --git a/src/shell-app.c b/src/shell-app.c index 916783a59..84b75beb9 100644 --- a/src/shell-app.c +++ b/src/shell-app.c @@ -1268,8 +1268,11 @@ apply_discrete_gpu_env (GAppLaunchContext *context, ShellGlobal *global) { GDBusProxy *proxy; - GVariant* variant; + GVariant *variant; guint num_children, i; + g_autoptr(GVariant) first_nondefault_discrete = NULL; + g_autoptr(GVariant) first_discrete = NULL; + g_autoptr(GVariant) first_nondefault = NULL; proxy = shell_global_get_switcheroo_control (global); if (!proxy) @@ -1289,19 +1292,47 @@ apply_discrete_gpu_env (GAppLaunchContext *context, for (i = 0; i < num_children; i++) { g_autoptr(GVariant) gpu = NULL; - g_autoptr(GVariant) env = NULL; g_autoptr(GVariant) default_variant = NULL; - g_autofree const char **env_s = NULL; - guint j; + g_autoptr(GVariant) discrete_variant = NULL; + gboolean is_default = FALSE; + gboolean is_discrete = FALSE; gpu = g_variant_get_child_value (variant, i); if (!gpu || !g_variant_is_of_type (gpu, G_VARIANT_TYPE ("a{s*}"))) continue; - /* Skip over the default GPU */ - default_variant = g_variant_lookup_value (gpu, "Default", NULL); - if (!default_variant || g_variant_get_boolean (default_variant)) + default_variant = g_variant_lookup_value (gpu, "Default", G_VARIANT_TYPE_BOOLEAN); + if (default_variant) + is_default = g_variant_get_boolean (default_variant); + + discrete_variant = g_variant_lookup_value (gpu, "Discrete", G_VARIANT_TYPE_BOOLEAN); + if (discrete_variant) + is_discrete = g_variant_get_boolean (discrete_variant); + + if (is_discrete) + { + if (first_nondefault_discrete == NULL && !is_default) + first_nondefault_discrete = g_variant_ref (gpu); + + if (first_discrete == NULL) + first_discrete = g_variant_ref (gpu); + } + + if (first_nondefault == NULL && !is_default) + first_nondefault = g_variant_ref (gpu); + } + + GVariant *gpu_list[] = { first_nondefault_discrete, first_discrete, first_nondefault }; + + for (i = 0; i < G_N_ELEMENTS (gpu_list); ++i) + { + GVariant *gpu = gpu_list[i]; + g_autoptr(GVariant) env = NULL; + g_autofree const char **env_s = NULL; + guint j; + + if (!gpu) continue; env = g_variant_lookup_value (gpu, "Environment", NULL);